<?php 
/*
 module:		基本配置控制器
 create_time:	2022-08-10 18:44:12
 author:		
 contact:		
*/

namespace app\admin\controller;
use app\admin\model\AccountAddress as AccountAddressModel;
use think\exception\ValidateException;
use app\admin\model\Baseconfig as BaseconfigModel;
use app\admin\model\Historyprice as HistorypriceModel;
use think\facade\Db;

class Baseconfig extends Admin {


	/*
 	* @Description  配置表单
 	*/
	public function index(){
		if (!$this->request->isPost()){
			return view('index');
		}else{
			$data = $this->request->post();
			$this->validate($data,\app\admin\validate\Baseconfig::class);

		$data['keyword'] = implode(',',$data['keyword']);

			$info = BaseconfigModel::column('data','name');
			foreach ($data as $key => $value) {

				if(array_key_exists($key,$info)){
					BaseconfigModel::field('data')->where(['name'=>$key])->update(['data'=>$value]);
				}else{
					BaseconfigModel::create(['name'=>$key,'data'=>$value]);
                }
			}
			return json(['status'=>200,'msg'=>'操作成功']);
		}
	}


	/*
 	* @Description  修改信息之前查询信息的 勿要删除
 	*/
	function getInfo(){
		$res = BaseconfigModel::column('data','name');
		$res['keyword'] = explode(',',$res['keyword']);
		$res['water_alpha'] = (int)$res['water_alpha'];

		$data['status'] = 200;
		$data['data'] = $res;
		return json($data);
	}


    /**
     * 交易数据列表
     * @return \think\response\Json|\think\response\View
     * @throws \think\db\exception\DbException
     */
    function transaction_list(){
        if(empty($this->request->post())){
            return view('index');
        }else{
            $limit  = $this->request->post('limit', 20, 'intval');
            $page = $this->request->post('page', 1, 'intval');
            $order  = $this->request->post('order', '', 'serach_in');	//排序字段
            $sort  = $this->request->post('sort', '', 'serach_in');		//排序方式
            $where = [];

            $orderby = ($sort && $order) ? $sort.' '.$order : 'id desc';
            //获取账号列表
            $res = HistorypriceModel::getList($page,$limit,formatWhere($where),$orderby);

            $data['status'] = 200;
            $data['data'] = $res;
            return json($data);
        }
    }




}

